package com.itheima.web.controller;

import com.itheima.domain.db.Questions;
import com.itheima.domain.vo.SoulTestQuestionVo;
import com.itheima.web.service.SoulTestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * desc
 *
 * @author mu
 * @date 2021/3/2 17:07
 */
@RestController
@RequestMapping("/soulTest")
public class SoulTestController {

    @Autowired
    private SoulTestService soulTestService;

    /**
     * 根据问题id获取问题及该问题全部选项
     * @param id 问题id
     * @return org.springframework.http.ResponseEntity
     * @version 0.1.0
     * @author Your name or email
     * @date 2021/3/3 18:26
     * @since 0.1.0
     */
    @GetMapping("/getById/{id}")
    public ResponseEntity getQuestionAndOptions(@PathVariable("id") String id) {
        return soulTestService.getQuestionAndOption(id);
    }
    /**
     * 新增或更新(若问题已存在)性格测试问题
     * @param data 问题数据
     * @return org.springframework.http.ResponseEntity
     * @version 0.1.0
     * @author Your name or email
     * @date 2021/3/3 18:29
     * @since 0.1.0
     */
    @PostMapping("/insertOrUpDate")
    public ResponseEntity insertOrUpdate(@RequestBody SoulTestQuestionVo data) {
        System.out.println(data);
        return soulTestService.insertOrUpdateQuestion(data);
    }

    /**
     * 罗杰-分页查询试卷列表
     * @param pageNumber 页码
     * @param pageSize 查询几条
     * @param cid 试卷id
     * @return
     */
     @GetMapping("/look")
    public ResponseEntity findById(@RequestParam(defaultValue = "1") Integer pageNumber,
                                          @RequestParam(defaultValue = "3")Integer pageSize,
                                          @RequestParam Integer cid){
        return soulTestService.findList(pageNumber,pageSize,cid);
    }

}
